#ifndef _TERRAIN_H_
#define _TERRAIN_H_

#include "d3dUtil.h"



class Terrain
{
private:
	DWORD mNumRows;
	DWORD mNumCols;

	DWORD mNumVertices;
	DWORD mNumIndices;

	ID3D10Device	*md3dDevice;

	ID3D10Buffer	*mVertexBuffer;
	ID3D10Buffer	*mIndexBuffer;
	ID3D10ShaderResourceView	*mDiffuseMapRV;
	ID3D10ShaderResourceView	*mSpecularMapRV;

	D3DXMATRIX mWorldMatrix;
	D3DXMATRIX mTexMatrix;

public:
	Terrain() : mNumRows(0), mNumCols(0), mNumVertices(0), mNumIndices(0),
	md3dDevice(0), mVertexBuffer(0), mIndexBuffer(0), mDiffuseMapRV(0), mSpecularMapRV(0) {
		D3DXMatrixIdentity(&mWorldMatrix);
		D3DXMatrixIdentity(&mTexMatrix);
	}
	virtual ~Terrain() {
		ReleaseCOM(mVertexBuffer);
		ReleaseCOM(mIndexBuffer);
		ReleaseCOM(mDiffuseMapRV);
		ReleaseCOM(mSpecularMapRV);
	}

	float getHeight(float x, float z) const;

	void init(ID3D10Device *device, DWORD m, DWORD n, float dx);
	void update(float dt);
	void draw();
	
	D3DXMATRIX	getWorldMatrix();
	D3DXMATRIX	getTexMatrix();
	ID3D10ShaderResourceView* getDiffuseMap(ID3D10ShaderResourceView* defaultMap);
	ID3D10ShaderResourceView* getSpecularMap(ID3D10ShaderResourceView* defaultMap);

	static const float HEIGHT_AMP;
	static const float HEIGHT_ANG;

private:
	void buildBuffers(ID3D10Device *device, DWORD m, DWORD n, float dx);
	void buildResourceViews();
};


#endif//_TERRAIN_H_
